<?php
namespace app\app\controller\v1;
use think\Db;
use think\Request;
use app\app\util\OnlineUtils;
class MyPropController extends BaseController{


    /**
     * @return array
     * [我的道具]
     */
    public function showMyProp()
    {
		$user_id = OnlineUtils::getUserIdBySid();
        $my_prop = Db::name('my_prop')->alias('a')->join('prop b','a.prop_id=b.id','left')
            ->field('a.id,a.num,a.prop_id,b.name,b.img,b.img2,b.img3')
            ->where('a.user_id','eq',$user_id)->where('prop_id','lt',11)->select();
        foreach($my_prop as $k => $v){
            $my_prop[$k]['img'] = 'http://ftadm.douxiangzhuan.cn/static/admin/prop/'.$my_prop[$k]['img'];
            $my_prop[$k]['img2'] = 'http://ftadm.douxiangzhuan.cn/static/admin/prop/'.$my_prop[$k]['img2'];
            $my_prop[$k]['img3'] = 'http://ftadm.douxiangzhuan.cn/static/admin/prop/'.$my_prop[$k]['img3'];
        }
        return ft(200,'success',$my_prop);
    }

    /**
     * @return array
     * [领取道具]
     */
    public function receiveProp()
    {
        $user_id = OnlineUtils::getUserIdBySid();         //获赠人id
        $id = input('get.id');                            //获赠记录
        $record = Db::name('my_give')->find($id);
        if ( $record['status'] == 0) {
            return ft(402,'该道具已经被领取');
        }elseif ( $record['status'] == 1){
            //获赠人的道具数量+1
            Db::query('update ft_my_prop set num = num + 1 where user_id='.$user_id.' and prop_id='.$record['prop_id']);
            //更改赠送记录的状态以及加入获赠人
            Db::name('my_give')->where('id','eq',$id)->update(['status'=>0,'give_user_id'=>$user_id]);
        }
    }

}
